const router = require('koa-router')(),
      mysql = require('mysql2/promise'),
      { course } = require('../models'),
      log = console.log;

router.prefix('/api/kdoing/course');


router.get('/getcourse/:cla_id', async (ctx, next) => {
  var { cla_id } = ctx.params;
  ctx.body = await course.getCourseByClaid(cla_id);
});
router.get('/getcoursebypage', async (ctx, next) => {
  var { page, limit } = ctx.query;
  ctx.body = await course.getCourseByPage(page, limit);
});
router.get('/getusercourse/:user_id', async (ctx, next) => {
  var { user_id } = ctx.params;
  ctx.body = await course.getCourseByUserid(user_id);
});
router.get('/getchildcourse/:course_id', async (ctx, next) => {
  var { course_id } = ctx.params;
  ctx.body = await course.getChildcourseByCourseid(course_id);
});
router.get('/getacourse/:course_id', async (ctx, next) => {
  var { course_id } = ctx.params;
  ctx.body = await course.getCourseByCourseid(course_id);
});
router.delete('/delcourse/:course_id', async (ctx, next) => {
  var { course_id } = ctx.params;
  ctx.body = await course.delCourseByCourseid(course_id);
});
router.get('/getcourseid', async (ctx, next) => {
  ctx.body = await course.getCourseid();
});
router.delete('/delchildcourse', async (ctx, next) => {
  var { course_id, cc_id } = ctx.request.body;
  ctx.body = await course.delChildcourse(course_id, cc_id);
});
module.exports = router;
